@extends('admin.layouts')
@section('style')
    <link rel="stylesheet" type="text/css" href="{{asset('public/js/minicolors/jquery.minicolors.css')}}">
    <style>
        html,body{
            height:100%;
        }
    </style>
@endsection
@section('main')

    <form class="layui-form luck-pane" id="form1" method="post">
        <div class="luck-content clearfix">
            <div class="layer-box">
                <div class="layui-tab-content layui-form-pane">
                    <div class="layui-tab-item layui-show">
                        {{csrf_field()}}
                        <input type="hidden" name="conf_id" value="{{$data->conf_id}}">
                        <div class="layui-form-item">
                            <label class="luck-form-label">{{trans('config.name')}}</label>
                            <div class="layui-input-inline">
                                <input type="text" name="conf_title" value="{{$data->conf_title}}" required jq-verify="required" jq-error="{{ trans('config.vali_required') }}" lay-verify="new_required" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="luck-form-label">{{trans('config.config')}}</label>
                            <div class="layui-input-inline">
                                <input type="text" name="conf_name" value="{{$data->conf_name}}" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="luck-form-label">{{trans('config.type')}}</label>
                            <div class="layui-input-inline" id="type">
                                <input type="radio" name="field_type" value="input" title="input" @if($data->field_type=='input') checked="" @endif>
                                <input type="radio" name="field_type" value="textarea" title="textarea" @if($data->field_type=='textarea') checked="" @endif>
                                <input type="radio" name="field_type" value="radio" title="radio" @if($data->field_type=='radio') checked="" @endif>
                            </div>
                        </div>
                        <div class="layui-form-item" id="radio-value" @if($data->field_type=='radio') style="display: block;" @else style="display: none;" @endif>
                            <label class="luck-form-label"></label>
                            <div class="layui-input-inline">
                                <input type="text" name="field_value" class="layui-input"><br>
                                <p><i class="fa fa-exclamation-circle yellow"></i>类型值只有在radio的情况下才需要配置，格式 1|开启,0|关闭</p>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="luck-form-label">{{trans('config.order')}}</label>
                            <div class="layui-input-inline">
                                <input type="text" name="conf_order"  value="{{$data->conf_order}}" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="luck-form-label">{{trans('config.description')}}</label>
                            <div class="layui-input-inline">
                                <textarea name="conf_tips" class="layui-textarea">{{$data->conf_tips}}</textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="luck-footer luck-footer-right luck-footer-padding">
            <div class="luck-block">
                <button class="layui-btn" lay-submit lay-filter="sub">{{trans('config.btn_submit')}}</button>
                <button class="layui-btn layui-btn-primary" type="button" id="close">{{trans('config.btn_close')}}</button>
            </div>
        </div>
    </form>

@endsection

@section('script')
    <script src="{{asset('public/js/jquery.min.js')}}"></script>
    <script src="{{asset('public/js/minicolors/jquery.minicolors.min.js')}}"></script>
    <script>
        $(document).ready( function() {
            $("#color").minicolors();
        })
        layui.use(['jquery','myform','layer','upload'],function(){
            var $= layui.jquery;
            var index = parent.layer.getFrameIndex(window.name);
            var form = layui.form();
            var load;
            $('#type>div').click(function(){
                if($(this).prev().val()=='radio'){
                    $('#radio-value').show();
                }else{
                    $('#radio-value').hide();
                }
            });

            form.verify({
                new_url:function(value){
                    if(!/(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/.test(value) && !this.new_required(value)){
                        return "{{ trans('config.vali_url') }}";
                    }
                },
                new_required:function(value){
                    if(!/[\S]+/.test(value)){
                        return "{{ trans('config.vali_required') }}";
                    }
                }
            });
            $('#close').click(function(){
                parent.layer.close(index);
            });

            form.on('submit(sub)', function(data){
                $.ajax({
                    url:"{{url('admin/configedit')}}",
                    type:"post",
                    data:data.field,
                    beforeSend:function(){
                        load=layer.load(1, {
                            shade: [0.1,'#fff']
                        });
                    },
                    success:function(data){
                        if(data.status==200){
                            layer.msg(data.msg,{icon:1,shift:5});
                            parent.layer.close(index);
                            if(data.url=="reload"){
                                parent.location.reload();
                            }
                        }else{
                            layer.msg(data.msg,{icon: 5,shift:6});
                        }
                    },
                    complete:function(){
                        layer.close(load);
                    },
                    error:function(){
                        layer.msg("{{trans('config.connect')}}",{icon: 5,shift:6});
                    }
                })
                return false;
            });
        });
    </script>
@endsection